package com.zzyl.serve.controller;

import java.time.LocalDateTime;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.serve.dto.AlertDataDto;
import com.zzyl.serve.dto.HandleAlertDataDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.serve.domain.AlertData;
import com.zzyl.serve.service.IAlertDataService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 报警数据Controller
 * 
 * @author iteheima
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/nursing/alertData")
@Api(tags = "报警数据相关接口")
@Slf4j
public class AlertDataController extends BaseController
{
    @Autowired
    private IAlertDataService alertDataService;

    /**
     * 查询报警数据列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:alertData:list')")
    @GetMapping("/list")
    @ApiOperation(value = "获取报警数据列表")
    public TableDataInfo<List<AlertData>> list(
            Integer pageNum,
            Integer pageSize,
            @ApiParam(value = "报警数据名称")
            @RequestParam(value = "deviceName", required = false) String deviceName,
            @ApiParam(value = "报警数据状态")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "开始时间")
            @RequestParam(value = "startTime", required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")LocalDateTime startTime,
            @ApiParam(value = "结束时间")
            @RequestParam(value = "endTime", required = false)
            @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")LocalDateTime endTime

    )
    {

        List<AlertData> list = alertDataService.selectAlertDataList(pageNum, pageSize, deviceName, status, startTime, endTime );
        return getDataTable(list);
    }



    /**
     * 获取报警数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('nursing:alertData:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取报警数据详细信息")
    public R<AlertData> getInfo(@ApiParam(value = "报警数据ID", required = true)
            @PathVariable("id") Long id)
    {
        return R.ok(alertDataService.selectAlertDataById(id));
    }

    /**
     * 新增报警数据
     */
    @PreAuthorize("@ss.hasPermi('nursing:alertData:add')")
    @Log(title = "报警数据", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增报警数据")
    public AjaxResult add(@ApiParam(value = "报警数据实体", required = true) @RequestBody AlertData alertData)
    {
        return toAjax(alertDataService.insertAlertData(alertData));
    }

    /**
     * 修改报警数据
     */
    @PreAuthorize("@ss.hasPermi('nursing:alertData:edit')")
    @Log(title = "报警数据", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改报警数据")
    public AjaxResult edit(@ApiParam(value = "报警数据实体", required = true) @RequestBody AlertData alertData)
    {
        return toAjax(alertDataService.updateAlertData(alertData));
    }

    /**
     * 删除报警数据
     */
    @PreAuthorize("@ss.hasPermi('nursing:alertData:remove')")
    @Log(title = "报警数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除报警数据")
    public AjaxResult remove(@ApiParam(value = "要删除的数据id的数组") @PathVariable Long[] ids)
    {
        return toAjax(alertDataService.deleteAlertDataByIds(ids));
    }
    /**
     * 处理报警数据
     */
    @PreAuthorize("@ss.hasPermi('nursing:alertData:handleAlertData')")
    @Log(title = "报警数据", businessType = BusinessType.UPDATE)
    @PutMapping("/handleAlertData")
    @ApiOperation("处理报警数据")
    public AjaxResult handleAlertData(
           @RequestBody HandleAlertDataDto handleAlertDataDto)
    {
        log.info("处理报警数据{},{},{}");

        return toAjax(alertDataService.handleAlertData(handleAlertDataDto));
    }
}
